package libra.tracking;

import java.util.Date;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.skywalking.apm.toolkit.trace.TraceContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import libra.tracking.thread.ThreadOneService;

@Controller
@RequestMapping("tracking")
public class TrackingController {
	@Autowired
	UnuseService unuseService;
	@Autowired
	UseService useService;
	
	@RequestMapping("unuse")
	@ResponseBody
	public Object unuse( HttpServletRequest req ){
		unuseService.doService(1,2,3);
		return Map.of("method","unuse");
	}
	
	@RequestMapping("use")
	@ResponseBody
	public Object use( HttpServletRequest req ){
		// 通过上下文对象可以绑定参数(key/value)进行传递
		TraceContext.putCorrelation("data", new Date().toString() );
		
		useService.doService(4,5,6);
		return Map.of("method","use");
	}
	
	
	//-------------------------------------
	
	@Autowired
	ThreadOneService threadOneService;
	@RequestMapping("threadOne")
	@ResponseBody
	public Object threadOne( HttpServletRequest req ){
		threadOneService.doThread();
		return Map.of("method","threadOne");
	}
	@RequestMapping("threadOne1")
	@ResponseBody
	public Object threadOne1( HttpServletRequest req ){
		threadOneService.doThread1();
		return Map.of("method","threadOne");
	}
	@RequestMapping("threadOne2")
	@ResponseBody
	public Object threadOne2( HttpServletRequest req ){
		threadOneService.doThread2();
		return Map.of("method","threadOne");
	}
}
